<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/common/taglib.jsp" %>
<html>
<head>
<link rel="stylesheet" href="${ctx}/static/css/lq.datetimepick.css">
<link rel="stylesheet" href="${ctx}/static/css/Master.css">
<script src="${ctx}/static/js/jquery-1.8.0.min.js"></script>
<script src="${ctx}/static/js/simpletooltip.min.js"></script>
<script src="${ctx}/static/js/selectUi.js"></script>
<script src="${ctx}/static/js/lq.datetimepick.js"></script>
<script type="text/javascript" src="${ctx}/static/js/jquery.validate.min.js"></script>
<link href="${ctx}/static/css/validation.css" type="text/css" rel="stylesheet"/>
<link rel="stylesheet" href="${ctx}/static/css/jquery-labelauty.css"/>
<script src="${ctx}/static/js/jquery-labelauty.js"></script>
<script type="text/javascript" src="${ctx}/static/js/jquery.metadata.js"></script>
<script src="${ctx}/static/plugins/layer/layer.js"></script>
<script type="text/javascript" src="${ctx}/static/js/messages_cn.js"></script>
<script src="${ctx}/static/plugins/My97DatePicker/WdatePicker.js"></script>
<%-- 基础js,所有页面都需要引入此js,依赖layer.js --%>
<script src="${ctx}/static/js/common/base.js"></script>
<script>
$(document).ready(function(){
	 var type =${advice.setTypeDetail};
	 $("#"+type).attr("checked","checked");
	 if(type!=11){
		 $("#yxorg").show();
		
		 
	 }
	$('.labelautybox :input').labelauty();
	
	 cc = $("#jg input[type=radio]:checked").val();//首先选中的id;
	 //alert(cc);
});

	
   var selectType=${advice.setTypeDetail}; //所选择的投放方式
   function change(id){
	   selectType = id;
	  if(id!="11"){
		  $("#yxorg").show();
	  }else{
		  $("#yxorg").hide();  
	  }
	  var context =$("#userNames").val();

	  if(context!=null&&context!=""){
		 top.layer.confirm('切换推送方式将清空当前推送方式所选数据,是否确认切换', {
		      btn: ['确认','取消'], //按钮
			    shade: false //不显示遮罩
			}, function(){
				//top.layer.msg('的确很重要', {icon: 1});确定
				 cc=id;
			     $("#userNames").val("");
			     $("#orgIds").val("");
			     top.layer.msg('数据已清除', {icon: 1});//确定
			}, function(){
				//alert(cc);
				 $("#"+cc).attr("checked","checked");
				 if(cc!="11"){
					 $("#yxorg").show();	
					}else{
					 $("#yxorg").hide();  
					}
			    //top.layer.msg('取消成功', {icon: 1});//取消
			    
			});  
	  }else{
		  cc=id;
	  }
  }
   
 //打开用户选择框
	function openUser(){
		//打开iframe层
		var index = parent.layer.open({
			title: '选择',
		    type: 2,
		   // offset:'30px',//垂直,水平
		    area: ['750px', '440px'],
		    fix: false, //不固定
		    maxmin: true,
		    content: '${ctx}/inform/'+selectType+'/chooseOrg',
		    success: function(layero, index){
		        //ifram对象
		        var $iframe = $(layero.find('iframe')[0]);
		        //ifram页面内容实际高度
		        var height = $iframe.contents().height();
		        //为保证美观,定义最大高度
		         var maxHeight = 500;
		        if(height>maxHeight){
		        	height=maxHeight;
		        }
		        $iframe.height(height);
		        //让layer弹出框的高度变成设置后的高度,使拖拽、最大/小化不会变成原高度
		        parent.layer.iframeAuto(index);
		    }
		});
	}
 
 
	$(function(){
		   var form;
		   $("#form1").validate({
				   
		       rules:{
		    	      advTitle:{
		                   required:true,
		                   maxlength:20
		                   
		               },
		               advDetails:{
		                   required:true,
		                   maxlength:500
		               },
		               startDateNew:{
		            	  required:true
		               }
		       
		       }
		   
		    
			   });
			   	    
		   });
		   
		    function formSubmit(){
			   var form=$("#form1");
			   if(!form.valid()){
				   return false;
			   }
			   
			   $.ajax({    
				    url:"${ctx}/inform/SaveEditInform",
				    data:form.serialize(),    
				    type:"POST",    
				    cache:false,    
				    dataType:"json",
				    async:false, //默认为true 异步    
				    success:function(data) {
				    	//alert(data);
				       // top.layer.msg(data,{},function(){
				        	  //alert("ssssssssssss");
				        	//window.location="${ctx}/announce/list";   
			            //});
				     
				       top.layer.msg(data,{},function()
				    		   {
				    	   window.location="${ctx}/inform/list";
				    		   });
				 
				     }
				});
		 
		   }
</script>
</head>



<body>

			<section class="boxRight">
				<div class="OrgTit">系统通知编辑</div>
				<div class="context">
				<form action="" id="form1">
					<div class="add_firstmenu">
					   <input type="hidden" name="advId" value="${advice.advId}">
						<dl>
							<dt>
								<span class="im">*</span>标题
							</dt>
							<dd>
								<input name="advTitle" type="text" class="w3" value="${advice.advTitle}" style="width:270;height:35"/>
							</dd>
						</dl>
						<dl>
							<dt>
								<span class="im">*</span>内容
							</dt>
							<dd>
								<div class="textareaBox w2">
									<textarea name="advDetails" >${advice.advDetails}</textarea>
								</div>
							</dd>
						</dl>
						<dl>
							<dt>
								开始时间
							</dt>
							<dd>
							<span class="date"><input name="startDateNew" type="text" placeholder="时间" id="datetimepicker" value="<fmt:formatDate value="${advice.startDate}" pattern="yyyy-MM-dd" />"  style="width:115;height:35"  class="Wdate" onclick="WdatePicker()"/></span>
							</dd>
						</dl>
						<dl>
							<dt class="org">
								<strong>投放设置</strong>
							</dt>
							<dd></dd>
						</dl>
						
						
						<dl>
							<dt>
								推送方式
							</dt>
							<dd>
								<div class="labelautybox labelautybox3">
									<div id="jg">
										<input type="radio" name="setTypeDetail" value="11" id="11" data-labelauty="全部机构" onclick="change('11')" checked="checked">
										<input type="radio" name="setTypeDetail" value="12" id="12" data-labelauty="按平台投放" onclick="change('12')">
										<input type="radio" name="setTypeDetail" value="13" id="13" data-labelauty="按渠道投放" onclick="change('13')">
										<input type="radio" name="setTypeDetail" value="14" id="14" data-labelauty="按物业投放" onclick="change('14')">
									</div>
									
								</div>
							</dd>
						</dl>
					<div id="yxorg" style="display:none">
						<dl>
							<dt>
								已选机构
							</dt>
							<dd>
								<div class="textareaBox" >
								   <input type="hidden" name="orgIds" id="orgIds" value="${advice.orgIds}">
									<textarea id="userNames" readonly="readonly"> <c:forEach
											items="${advice.orgList}" var="org" varStatus="status">${org.orgName}<c:if
												test="${!status.last}">,</c:if> </c:forEach>
									</textarea>
								</div>
								<a  href="javascript:void(0);" class="org" onclick="openUser()">编辑</a>
							</dd>
						</dl>
				</div>
				</form>
						<div class="combtn"><a href="javascript:void(0);" onclick="formSubmit()">保存</a><a href="javascript:void(0);" onclick="history.back();">返回</a></div>
					</div>
				</div>
			
			</section>
</body>
</html>